//
//  InfomationViewController.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/8/5.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "InfomationViewController.h"

@interface InfomationViewController ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *textField;

@end

@implementation InfomationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if([_type isEqualToString:@"0"]){
        self.title = @"修改昵称";
    }else{
        self.title = @"修改个性签名";
    }
    
    UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
    UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
    NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
    [bar setItems:buttonsArray];
    
    _textField = [[UITextField alloc]initWithFrame:CGRectMake(ScreenX375(24), ScreenX375(24), SCREEN_WIDTH - ScreenX375(48), 40)];
    _textField.backgroundColor = [UIColor whiteColor];
    //清楚按钮
    _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    //圆角
    _textField.layer.cornerRadius = 3.0;
    _textField.layer.masksToBounds = YES;
    _textField.inputAccessoryView = bar;
    _textField.text = [NSString stringWithFormat:@"%@",_value];
    _textField.font = [UIFont systemFontOfSize:13];
    _textField.delegate = self;
    [self.view addSubview:_textField];
    
    UIButton *saveBtn = [[UIButton alloc]initWithFrame:CGRectMake(ScreenX375(24), CGRectGetMaxY(_textField.frame)+ScreenX375(24), SCREEN_WIDTH - ScreenX375(48), 40)];
    [saveBtn setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(saveClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:saveBtn];
}

- (void)saveClick {
    if ([[_textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]!=0) {
        [self.changeIntroDelegate changeIntro:_textField.text withType:self.type];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)resignKey{
    [_textField resignFirstResponder];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
